﻿<UserControl x:Class="ConsoleHoster.View.Controls.CommandListEditor"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:uc="clr-namespace:ConsoleHoster.View.Controls"
             xmlns:cv="clr-namespace:ConsoleHoster.View.Converters"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="500">
    <UserControl.Resources>
        <cv:ObjectToVisibilityConverter x:Key="cvObjectToVisibilityConverter" />
    </UserControl.Resources>
    <Grid>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <Grid Margin="0, 0, 5, 0">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <ListView ItemsSource="{Binding Path=Commands}" SelectedValue="{Binding Path=SelectedCommand, Mode=TwoWay}" MinWidth="200">
                    <ListView.View>
                        <GridView AllowsColumnReorder="False" ColumnHeaderContainerStyle="{DynamicResource ResourceKey=gridViewHiddenHeaderStyle}">
                            <GridViewColumn DisplayMemberBinding="{Binding Path=FullName}"/>
                            <GridViewColumn Width="Auto">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <uc:TabCloseButton x:Name="btnRemoveCommand" Margin="0, 0, 3, 0" VerticalContentAlignment="Center"  ToolTip="Remove" Click="btnRemoveCommand_Click" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
                </ListView>

                <Button Content="New" Command="{Binding Path=NewCommandDataCommand}" Grid.Row="1" Cursor="Hand" Margin="0, 3, 0, 0" />
            </Grid>

            <Grid Grid.Column="1" Visibility="{Binding Path=SelectedCommand, Converter={StaticResource cvObjectToVisibilityConverter}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions >
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <TextBlock Text="Command name: " VerticalAlignment="Center" />
                <TextBox Text="{Binding Path=SelectedCommand.Name, Mode=TwoWay}" Grid.Column="1" Margin="1" />

                <TextBlock Text="Command text: " Grid.Row="1" VerticalAlignment="Center" />
                <TextBox Text="{Binding Path=SelectedCommand.CommandText, Mode=TwoWay}" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap" AcceptsReturn="True" ScrollViewer.VerticalScrollBarVisibility="Auto" Margin="1" />

                <TextBlock Text="Group name: " Grid.Row="2" VerticalAlignment="Center" />
                <TextBox Text="{Binding Path=SelectedCommand.GroupName, Mode=TwoWay}" Grid.Column="1" Grid.Row="2" Margin="1" />

                <TextBlock Text="Color: " Grid.Row="3" VerticalAlignment="Center" />
                <uc:ColorSelector ColorCode="{Binding Path=SelectedCommand.CommandColor, Mode=TwoWay}" Grid.Column="1" Grid.Row="3" Margin="1" />

                <CheckBox Content="Execute on run" IsChecked="{Binding Path=SelectedCommand.IsFinal, Mode=TwoWay}" Grid.Row="4" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="1" />

                <TextBlock Text="{Binding Path=ErrorMessage}" Grid.Row="5" Grid.ColumnSpan="2" Foreground="Red" Visibility="{Binding Path=ErrorMessage, Converter={StaticResource cvObjectToVisibilityConverter}}" FontWeight="Bold" Margin="1" />
            </Grid>
        </Grid>
    </Grid>
</UserControl>
